package com.prs.crm.dao.hr.impl;


import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.hr.RoleDao;
import com.prs.crm.dao.impl.BaseDaoImpl;

import com.prs.crm.domain.hr.Role;

public class RoleDaoImpl extends BaseDaoImpl<Role> implements RoleDao{
	
	@SuppressWarnings("unchecked")
	public List<Role> getAllRoles()
	{
		return (List<Role>)this.getHibernateTemplate().execute(
				new HibernateCallback()
				{
					public Object doInHibernate(Session session) throws HibernateException {
			        	Criteria criteria = session.createCriteria(Role.class);
			        	return criteria.list();
			        }   
				}
		);
		
	}
	@SuppressWarnings("unchecked")
	@Override
	public Role getByNameRole(final String name) {
		return (Role)this.getHibernateTemplate().execute(
				new HibernateCallback()
				{
					public Object doInHibernate(Session session) throws HibernateException {
			        	Criteria criteria = session.createCriteria(Role.class);
			        	criteria.add(Restrictions.eq("name", name));
			        	return criteria.list().get(0);
			        }   
				}
		);
		
	}
	
}
